<?php
/**
 * Created by PhpStorm.
 * User: pf
 * Date: 2017/12/7
 * Time: 14:29
 */

namespace App\Repositories;


use App\Http\Controllers\Admin\Scene\Repository\Spot;
use App\Service\WechatPageService;

class PageRepository
{
    protected $wechatPageService;
    protected $wechat;
    public function __construct()
    {
        $this->wechatPageService=new WechatPageService();
        $this->wechat=app('wechat');
    }
    public function addPage($post,$id){
        $title= $post['title'];
        $description=$post['desc'];
        $icon_url=$this->imageUpload($post['thumb']);
        $page_url=route('scene',['id'=>$id]);
        return   $this->wechatPageService->add($title,$description,$page_url,$icon_url);

    }
    public function updatePage($post,$model){
        $title= $post['title'];
        $description=$post['desc'];
        $icon_url=$this->imageUpload($post['thumb']);
        $page_url=route('scene',['id'=>$model->id]);
        return  $this->wechatPageService->update($model->page_id,$title,$description,$page_url,$icon_url);
    }
    //删除页面
    public function delete($id){
        $spot=Spot::find($id);
        $this->wechatPageService->delete($spot->page_id);
    }
    //微信上传素材
    public function imageUpload($image){
          $material = $this->wechat->material;
          $result=$material->uploadImage(storage_path('app/public/'.$image));
          return $result->url;
    }

}